"""
Para ativar o Dashboard deve colocar no settings.py:
    ADMIN_TOOLS_INDEX_DASHBOARD = 'Galaxy.dashboard.CustomIndexDashboard'

Para ativar o Dashboard da index de cada aplicativo deve colocar no settings.py:
    ADMIN_TOOLS_APP_INDEX_DASHBOARD = 'Galaxy.dashboard.CustomAppIndexDashboard'
"""

from django.utils.translation import ugettext_lazy as _
from django.core.urlresolvers import reverse

from admin_tools.dashboard import modules, Dashboard, AppIndexDashboard
from admin_tools.utils import get_admin_site_name


class CustomIndexDashboard(Dashboard):
    """
    Dashboard do Projeto (Galaxy)
    """
    columns =2
    def init_with_context(self, context):

        site_name = get_admin_site_name(context)
        # append a link list module for "quick links"
        #self.children.append(modules.LinkList(
        #   _('Links Rapidos'),
        #    layout='inline',
        #    draggable=False,
        #    deletable=True,
        #    collapsible=False,
            #children=[
            #    [_('Retornar ao Instituto Galaxy'), '/'],
            #    [_('Alterar senha'),
            #     reverse('%s:password_change' % site_name)],
            #    [_('Sair'), reverse('%s:logout' % site_name)],
            #]
        #))
        # Listar administracao do BackEnd (Ingenium)
        self.children.append(modules.AppList(
            _('Ingenium: Aplicacao e Administracao do BackEnd'),
            models=('ingenium.models.*',)
        ))
         # Listar administracao do FrontEnd (Publicacao)
        self.children.append(modules.AppList(
            _('Site: Sistema de Administracao do FrontEnd'),
            models=('publicacoes.models.*',)
        ))

        
        # append a recent actions module
        self.children.append(modules.RecentActions(_('Recent Actions'), 5))

        self.children.append(modules.Group(
            title="Ferramentas Adicionais",
            display = "tabs",
            children = [
                modules.AppList(
                    _('Newsletter'),
                    models=('emencia.django.newsletter.models.*',),
               ),
                modules.AppList(
                    _('Mensagens'),
                    models=('mensagens.models.*',),
               ),
                modules.AppList(
                    _('Publicidade'),
                    models=('publicidade.models.*',),
               ),
                modules.AppList(
                    _('Taggings: Sistema de Tags de Noticia'),
                    exclude=('publicidade.models.*','mensagens.models.*','django.contrib.*','ingenium.models.*','publicacoes.models.*','emencia.django.newsletter.models.*',),
                )
            ]
        ))
        # append a feed module
        #self.children.append(modules.Feed(
        #    _('Ultimas Noticias do Instituto Galaxy'),
        #    feed_url='http://www.djangoproject.com/rss/weblog/',
        #    limit=5
        #))

        # append another link list module for "support".
        self.children.append(modules.LinkList(
            _('Links Auxiliares'),
            children=[
                {
                    'title': _('Instituto Galaxy'),
                    'url': 'http://www.institutogalaxy.com.br/',
                    'external': True,
                    'description': 'Direciona para o site do Instituto Galaxy',
                },
                {
                    'title': _('Gmail'),
                    'url': 'http://mail.google.com/mail?hl=pt-BR',
                    'external': True,
                    'description': 'Direciona para o Gmail',
                },
                {
                    'title': _('Hotmail'),
                    'url': 'http://www.hotmail.com/',
                    'external': True,
                    'description': 'Direciona para o Hotmail',
                },
                {
                    'title': _('Facebook'),
                    'url': 'http://www.facebook.com.br/',
                    'external': True,
                    'description': 'Direciona para o Facebook',
                },
                {
                    'title': _('Orkut'),
                    'url': 'http://www.orkut.com/',
                    'external': True,
                    'description': 'Direciona para o Orkut',
                },
                {
                    'title': _('Twitter'),
                    'url': 'http://www.twitter.com/',
                    'external': True,
                    'description': 'Direciona para o Twitter',
                },
            ]
        ))


class CustomAppIndexDashboard(AppIndexDashboard):
    """
    Personalizar o Dashboard Index das Aplicacoes (Ingenium, Publicacoes, Tagging, Newsletter)
    """

    title = 'STW - Solucoes Tecnologicas para Web'

    def __init__(self, *args, **kwargs):
        AppIndexDashboard.__init__(self, *args, **kwargs)
        
        # append a model list module and a recent actions module
        self.children += [
            modules.ModelList(self.app_title, self.models),
            modules.RecentActions(
                _('Recent Actions'),
                include_list=self.get_app_content_types(),
                limit=5
            )
        ]

    def init_with_context(self, context):
        """
        Use this method if you need to access the request context.
        """
        return super(CustomAppIndexDashboard, self).init_with_context(context)
